#include "newSettingWindow.h"


newSettingWindow::newSettingWindow(QWidget* parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);

	initConnect();


}

newSettingWindow::~newSettingWindow()
{}

void newSettingWindow::initConnect()
{
	connect(ui.okBtn, SIGNAL(clicked()), this, SLOT(on_okBtn_clicked()));
	connect(ui.concelBtn, &QPushButton::clicked, this, &newSettingWindow::on_concelBtn_clicked);
	connect(ui.pngPix, SIGNAL(activated(int)), this, SLOT(on_comboboxChanged(int)));
	connect(ui.pathBtn, SIGNAL(clicked()), this, SLOT(on_pathBtnClicked()));

}

static int addId = 1;
void newSettingWindow::on_okBtn_clicked()
{

	std::cout << __FUNCTION__ << std::endl;

	_width = ui.widthPng->text().toInt();
	_height = ui.heightPng->text().toInt();

	_job.workId = "ooxx" + QString(addId);
	_job.workVersion = "1."+QString(addId);
	addId++;
	
	_job.workName = ui.fileName->text();
	_job.workPath = ui.filePath->text();
	_job.workDraw = ui.fileReadme->toPlainText();
	_job.workPix = ui.widthPng->text() + "*" + ui.heightPng->text();

	QTime time;

	_job.workTime = time.currentTime().toString();

	if (ui.radioButtonTemlate->isChecked()) _isNew = false;



	//bool ret = UseMySQL::instance()->insertWork(_job);
	//if (!ret) {
	//	qDebug() << "insert falied.";
	//}

	qDebug() << _job.workPix << "-" << _job.workTime;

	close();
}

void newSettingWindow::on_pathBtnClicked()
{
	QString openFileName = QFileDialog::getOpenFileName(this,
															"dry-打开文档",
															"正在打开一个文档!",
															"图片文件(*.png);;"
															"所有文件1(*.*)");

	if (openFileName.isEmpty()) {
		qDebug() << "open failed.";
		return;
	}
	qDebug() << openFileName;
	
	ui.filePath->setText(openFileName);

}

void newSettingWindow::on_concelBtn_clicked()
{
	std::cout << __FUNCTION__ << std::endl;

	close();

}

void newSettingWindow::on_comboboxChanged(int index)
{

	if (ui.pngPix->currentText().toStdString() == "固定") {
		ui.widthPng->setText("1920");
		ui.heightPng->setText("1080");
		ui.widthPng->setEnabled(false);
		ui.heightPng->setEnabled(false);
	}
	else {
		ui.widthPng->setEnabled(true);
		ui.heightPng->setEnabled(true);
	}

}
